#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using i128 = __int128;
const int MOD = 998244353;
ll powm(ll a, ll b, ll mod){
    ll res = 1;
    a %= mod;
    if(a < 0) a += mod; 
    while(b > 0){
        if(b & 1){
            res = (i128(res) * a) % mod;
        }
        a = (i128(a) * a) % mod;
        b >>= 1;
    }
    return res;
}
bool is_prime(ll m){
    if(m < 2) return false;
    for(auto p : {2LL, 3LL, 5LL, 7LL, 11LL, 13LL, 17LL, 19LL, 23LL, 29LL, 31LL, 37LL}){
        if(m % p == 0){
            return m == p;
        }
    }
    auto mul = [&](ll a, ll b, ll mod) -> ll {
        i128 res = (i128(a) * b) % mod;
        return res;
    };
    auto power = [&](ll a, ll d, ll mod) -> ll {
        ll res = 1;
        a %= mod;
        while(d > 0){
            if(d & 1){
                res = mul(res, a, mod);
            }
            a = mul(a, a, mod);
            d >>= 1;
        }
        return res;
    };
    auto mr = [&](ll n, ll a) -> bool {
        if(n % a == 0) return false;
        ll d = n-1;
        int s = 0;
        while(d % 2 == 0){
            d /= 2;
            s +=1;
        }
        ll x = power(a, d, n);
        if(x == 1 || x == n-1) return true;
        for(int r=1; r<s; r++){
            x = mul(x, x, n);
            if(x == n-1) return true;
        }
        return false;
    };
    vector<ll> bases;
    if(m < 1373653){
        bases = {2, 3};
    }
    else if(m < 9080191){
        bases = {31, 73};
    }
    else if(m < 4759123141LL){
        bases = {2, 7, 61};
    }
    else{
        bases = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37};
    }
    for(auto a : bases){
        if(!mr(m, a)){
            return false;
        }
    }
    return true;
}
ll n_sub1, res_sub1, m_sub1;
ll cas = 0;
void dfs(int pos, ll cp, ll n_max, ll m_max, ll target_res){
    if(pos == n_max){
        if(cp % m_max == target_res){
            cas = (cas + 1) % MOD;
        }
        return;
    }
    for(ll a = 0; a < m_max; ++a){
        dfs(pos + 1, (cp * a) % m_max, n_max, m_max, target_res);
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, res, m;
    cin >> n >> res >> m;
    if(n <=5 && m <=10){
        n_sub1 = n;
        res_sub1 = res;
        m_sub1 = m;
        cas = 0;
        if(n ==0){
            if(res == (1 % m)){
                cout << 1 % MOD << "\n";
            }
            else{
                cout << 0 << "\n";
            }
            return 0;
        }
        dfs(0, 1, n_sub1, m_sub1, res_sub1);
        cout << cas % MOD << "\n";
        return 0;
    }
    if(res ==0 && is_prime(m)){
        ll a = m % MOD;
        ll b = (m -1) % MOD;
        auto fpow = [&](ll base, ll exp) -> ll {
            return powm(base, exp, MOD);
        };
        ll A = fpow(a, n);
        ll B = fpow(b, n);
        ll ans = (A - B + MOD) % MOD;
        cout << ans << "\n";
        return 0;
    }
    cout << "0\n";
    return 0;
}
